package com.aabte.commons.errorcodetest;

import org.springframework.stereotype.Service;

/**
 * @author Daniel
 * @version 1.0
 * @date 2020/4/30
 */
@Service
public class MockService {

  public UserDTO getUser(Long id) {
    UserDTO user = queryUserFromDb(id);
    UserCodeEnum.USER_NOT_FOUND.checkNotNull(user, "User {0} not found.", id);
    return user;
  }

  private UserDTO queryUserFromDb(Long id) {
    if (id % 2 == 0) {
      return null;
    }
    return UserDTO.builder().uid(id).username("tom").build();
  }

  public UserDTO addUser(UserParam userParam) {
    return UserDTO.builder().uid(userParam.getId()).username(userParam.getUsername()).build();
  }
}
